<#include "../common/layout.ftl"/>
<@layout>
<div class="well" style="width: 44%;float: left">
	<span class="label label-success">修改会员资料</span>
	<#if member.user_type==0>
	<form id="form1" class="well form-horizontal" action="../update"  method="post">
	  <input name="member.id"  type="hidden" value="${member.id}" >
	  <input name="member.cell_phone"  type="hidden" value="${member.cell_phone}" >
      <div class="control-group">
        <label class="control-label" for="focusedInput">手机号码：</label>
        <div class="controls" >
          ${member.cell_phone}
        </div>
      </div>
        <div class="control-group">
        <label class="control-label" for="focusedInput">真实姓名：</label>
        <div class="controls" >
          <input class="input-xlarge focused" name="member.real_name" id="realname" type="text"  style="height: 26"  value="${member.real_name}">
        </div>
      </div>
       <!--<div class="control-group">
        <label class="control-label" for="focusedInput">车牌号码：</label>
        <div class="controls" >
          <input class="input-xlarge focused" name="member.plage_number" id="plage_number" type="text"  style="height: 26"  value="${member.plage_number!""}">
        </div>
      </div>-->
       <div class="control-group">
        <label class="control-label" for="focusedInput">性别：</label>
        <div class="controls" >
        	<select id="sex" name="member.sex">
                <option value="0" <#if member.sex==0 >selected</#if>>男</option>
                <option value="1" <#if member.sex==1 >selected</#if>>女</option>
                <option value="2" <#if member.sex==2 >selected</#if>>未知</option>
              </select>
        </div>
      </div>
      <div class="control-group">
        <label class="control-label" for="focusedInput">允许签单：</label>
        <div class="controls" >
        	<#if member.is_deal==0>
        		<input name="is_deal" id="isdeal" type="checkbox">
        	<#else>
        		<input name="is_deal" id="isdeal" type="checkbox" checked="checked">
        	</#if>
        </div>
      </div>
      <div class="form-actions">
        <button type="submit" class="btn btn-primary" onsubmit="save()">确 定</button>
        <button type="reset" class="btn">重 置</button>
      </div>
  </form>
  </div>
  <#else>
  	<form id="form2" class="well form-horizontal" action="../updateOrign"  method="post">
	  <input name="member.id"  type="hidden" value="${member.id}" >
	  <input type="hidden" name="tels" id="tels"/>
      <div class="control-group">
        <label class="control-label" for="focusedInput">单位名称：</label>
        <div class="controls" >
          ${member.user_name}
        </div>
      </div>
        <div class="control-group">
        <label class="control-label" for="focusedInput">联系人：</label>
        <div class="controls" >
          <input class="input-xlarge focused" name="member.real_name" id="realname" type="text"  style="height: 26"  value="${member.real_name!""}">
        </div>
      </div>
      <div class="control-group">
        <label class="control-label" for="focusedInput">联系电话：</label>
        <div class="controls" >
          <input class="input-xlarge focused" name="member.cell_phone" id="cell_phone" type="text"  style="height: 26"  value="${member.cell_phone!""}">
        </div>
      </div>
       <div class="control-group">
        <label class="control-label" for="focusedInput">单位地址：</label>
        <div class="controls" >
        	<input class="input-xlarge focused" name="member.adds" id="adds" type="text"  style="height: 26"  value="${member.adds!""}">
        </div>
      </div>
      <div class="control-group">
        <label class="control-label" for="focusedInput">备注：</label>
        <div class="controls" >
        	<input class="input-xlarge focused" name="member.remark" id="remark" type="text"  style="height: 26"  value="${member.remark!""}">
        </div>
      </div>
      <div class="control-group">
        <label class="control-label" for="focusedInput">允许签单：</label>
        <div class="controls" >
        	<#if member.is_deal==0>
        		<input name="is_deal" id="isdeal" type="checkbox">
        	<#else>
        		<input name="is_deal" id="isdeal" type="checkbox" checked="checked">
        	</#if>
        </div>
      </div>
      <div class="form-actions">
        <button type="button" class="btn btn-primary" id="save" name="save">确 定</button>
        <button type="reset" class="btn">重 置</button>
      </div>
  </form>
</div>
  <div id="orgin_tel" class="well-tel" style="width: 49%;">
		<span class="label label-success">关联手机(至少写一条)</span>
	      	<br/>
	      	<input type="button" id="addTel" value="增加行"></input>
			<input type="button" id="delTel" value="删除行"></input>
		        <table id="telTab" name="telTab">
		        	<tr>
		        		<th></th>
		        		<th>手机号</th>
		        		<th>姓名</th>
		        		<th>常用目的地</th>
		        		<th>车牌号</th>
		        	</tr>
					<#list telList as tel>
						<tr>
							<td>
								<input name="select" type="checkbox" value=""/>
							</td>
							<td>
								<input type="text" value="${tel.telephone}"/>
							</td>
							<td>
								<input type="text" value="${tel.name}"/>
							</td>
							<td>
								<input type="text" value="${tel.address}"/>
							</td>
							<td>
								<input type="text" value="${tel.car_id}"/>
							</td>
						</tr>
					</#list>
		        </table>
  </div>
  </#if>

 <script>
  $(document).ready(function(){ 
	$('#addTel').click(function(){
		debugger;
		var newRow="<tr><td><input name='select' type='checkbox' /></td><td><input type='text'/>"+
					"</td><td><input type='text'></td><td><input type='text'>"+
					"</td><td><input type='text'></td></tr>";
		$('#telTab tr:last').after(newRow);
		});
	$('#delTel').click(function(){
		debugger;
		var ckbs=$("#telTab input:checked");
		if(ckbs.size()==0){
	        alert("要删除指定行，需选中要删除的行！");
	        return;
	     }
         ckbs.each(function(){
            $(this).parent().parent().remove();
         });
	});
	
	$('#save').click(function(){
			 debugger;
			 var tels=[];
			//操作 table
			var $trAry = $("table#telTab tr");
			if($trAry.length==0){
				alert("必须有一条手机号");
				return;
			}
			for (var i = 1; i < $trAry.length; i++) {
				var $tr = $($trAry[i]);
				var $tdAry =  $tr.find("td");
				var tel={};
				if($($tdAry[1]).find('input').val()==""){
					alert("手机号不可为空");
					return false;
				}
				//for(var j=0;i<$tdAry.length;j++){
					//tel.is_deal=$($($tdAry[0]).find('input')).attr("checked");
				tel.telephone=$($tdAry[1]).find('input').val();
				tel.name=$($tdAry[2]).find('input').val();
				tel.address=$($tdAry[3]).find('input').val();
				tel.car_id=$($tdAry[4]).find('input').val();
				//}
				tels[i-1]=tel;
			}
			$('#tels').val(JSON.stringify(tels));
			$('#form2').submit();
		});

	

  });
$(function() { 
		$("#form1").validity(function() {
	        $("#realname").require();
	        $("#cellphone").require().match("number");
	        $("#plage_number").require();
	    });
		 
		 $("#form2").validity(function(){
			 debugger;
			$('#realname').require();
			$('#adds').require();
		 });
 });
</script>

</@layout>